package com.banyuan;

import java.io.*;
import java.util.Date;

/*
* 把对象存到电脑文件中
*
* */
public class ObjectOutputStreamTest {
    public static void main(String[] args) {
        OutputStream os = null;
        ObjectOutputStream oos = null;

        try {
            String s = "123";
            Date date = new Date();
            Student student = new Student();
            os = new FileOutputStream("/Users/edy/Desktop/file/obj.txt");
            oos = new ObjectOutputStream(os);
            oos.writeObject(s);
            oos.writeObject(date);
            oos.writeObject(student);
            oos.writeObject(null);

            oos.flush();   //一次写入

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            IOUtilis.closeQuiety(oos);
            IOUtilis.closeQuiety(os);
        }

    }
}
